<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class LoginRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'username' => 'required|string|max:255|regex:/^[a-zA-Z0-9_]+$/',
            'password' => 'required|string|max:255',
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     */
    public function messages(): array
    {
        return [
            'username.required' => '用户名不能为空',
            'username.regex' => '用户名只能包含字母、数字和下划线',
            'username.max' => '用户名长度不能超过255个字符',
            'password.required' => '密码不能为空',
            'password.max' => '密码长度不能超过255个字符',
        ];
    }
}

